This package is for giving utils for web servers supporting the following web frameworks:
- actix
- rocket
- axum
- hyper
These will help the developer use these tools outside of the box to have uniform runtime states, config handles, and error handling for api endpoints. This will enable developers to fuse servers together to call endpoints via memory.
Error handling
This package has errors that can be imported with the following statement:
use ;
The NanoServiceError
is the error struct that handles the message and the error status of the error. To construct an error, you can use the following:
let error = new
The NanoServiceErrorStatus
will convert to a HTTP response code that corresponds with the message. Without any feature selection, the error will just be an error. However, if you select one or more of the following features:
- axum
- actix
- rocket
- hyper
The error will be able to be converted to that framework's HTTP response. This means that your library can return NanoServiceError
structs for errors and these errors will be able to convert into HTTP responses for those webframeworks.
You can also map any expression returning a Result
to return a NanoServiceError
on error with the code below:
use nanoservices_utils::safe_eject;
let some_outcome = safe_eject!(some_function());
To see how error handling works for web frameworks, lets look at the following example where we have a function that will not allow a number more than 10 with the following code:
use ;
We can then call this function and exploit the ?
operator to return a HTTP response automatically if an error is thrown with the following frameworks:
Actix
use ;
use NanoServiceError;
use Deserialize;
pub async
Axum
use ;
use NanoServiceError;
use Deserialize;
pub async
Rocket
use Json;
use NanoServiceError;
use Status;
use Deserialize;
// Specify that Rocket's `serde` should be used
pub async
Beta Utils
I'm currently supporting the following utils:
- JWT
- Config
- error handling for server endpoints
- runtime state
but these are not polished